s = 'Elements are written as "<tag>text</tag>".'
import html
print(s)
print(html.escape(s)) # html转义,某些字符被替换成了十六进制的转义序列

print(html.escape(s,quote=False))  # html转义,引号不转义

# 处理ASCii文本，嵌入非ascii文本
s = 'Spicy Jalapeño'
s.encode('ascii',errors='xmlcharrefreplace')



s1 = 'Spicy &quot;Jalape&#241;o&quot.'
from html.parser import HTMLParser
import html
html.unescape(s1) # 处理转义后的字符
